﻿using System;
using System.Management;

namespace ClusterAwareProperties
{
    /// <summary>
    /// Wrapper class EventResourceStateChange ManagementObject
    /// </summary>
    public class EventResourceStateChangePropety
    {

        #region ctor

        /// <summary>
        /// constuctor
        /// </summary>
        private EventResourceStateChangePropety()
        {
            EventObjectType = ObjectTypeEvent.Unknown;
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="queryobj">EventResourceStateChange ManagementObject instance</param>
        public EventResourceStateChangePropety(ManagementBaseObject queryobj)
            : this()
        {
            this.Convert(queryobj);
        }


        #endregion

        #region public properties

        /// <summary>
        /// Provides the unique value that indicates the time at which the event was generated. 
        /// This is a 64-bit value that represents the number of 100-nanosecond intervals after January 1, 1601. 
        /// The information is in the Coordinated Universal Times (UTC) format.
        /// </summary>
        public DateTime? TimeCreated { get; internal set; }

        /// <summary>
        /// Provides the security descriptor used by the event provider to determine which users can receive the event.
        /// </summary>
        public UInt16[] SecurityDescriptor { get; internal set; }
        /// <summary>
        /// Provides the major event category. A value of 0 indicates an event returned by GetClusterNotify.
        /// </summary>
        public UInt32 EventTypeMajor { get; internal set; }
        /// <summary>
        /// Provides the subtype within the major category. When the EventTypeMajor property is 0, this subtype contains the cluster event value that GetClusterNotify returns.
        /// </summary>
        public UInt32 EventTypeMinor { get; internal set; }
        /// <summary>
        /// Provides the name of the object to which this event applies.
        /// </summary>
        public string EventObjectName { get; internal set; }
        /// <summary>
        /// Provides the type of object to which this event applies.
        /// </summary>
        public ObjectTypeEvent EventObjectType { get; internal set; }
        /// <summary>
        /// Provides the WMI path of the object to which this event applies.
        /// </summary>
        public string EventObjectPath { get; internal set; }
        
        /// <summary>
        /// Current state of the object that is reporting a state change.
        /// </summary>
        public UInt32 EventNewState { get; internal set; }

        /// <summary>
        /// Description of EventNewState
        /// </summary>
        public string EventDescriptionNewState
        {
            get
            {
                switch (EventObjectType)
                {
                    case ObjectTypeEvent.Node:
                        return Enum.GetName(typeof(NodeState), EventNewState);
                    case ObjectTypeEvent.Group:
                        return Enum.GetName(typeof(StateGroupResources), EventNewState);
                    case ObjectTypeEvent.Resources:
                        return Enum.GetName(typeof(StateResources), EventNewState);
                    case ObjectTypeEvent.Network:
                        return Enum.GetName(typeof(StateNetwork), EventNewState);
                    case ObjectTypeEvent.NetworkInterface:
                        return Enum.GetName(typeof(StateNetworkInterface), EventNewState);
                }
                return "Unknown";
            }
        }

        /// <summary>
        /// Current node that is hosting this group.
        /// </summary>
        public string EventNode { get; internal set; }

        /// <summary>
        /// Current group that contains this resource.
        /// </summary>
        public string EventGroup { get; internal set; }

        #endregion
    }
}
